package com.ttg.web.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.model.mapper.MobileSmsMapper;
import com.ttg.model.pojo.MobileSms;
import com.ttg.web.service.MobileSmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class MobileSmsServiceImpl extends ServiceImpl<MobileSmsMapper,MobileSms> implements MobileSmsService {
    @Override
    public int countByMobile(String smsMobile, LocalDateTime gtTime) {
        LambdaQueryWrapper<MobileSms> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(MobileSms::getSmsMobile, smsMobile)
                .gt(MobileSms::getSmsAddTime, gtTime);
        return count(wrapper);
    }

    @Override
    public int countByMobile(String smsMobile, LocalDateTime sDate, LocalDateTime eDate) {
        LambdaQueryWrapper<MobileSms> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(MobileSms::getSmsMobile, smsMobile)
                .ge(MobileSms::getSmsAddTime, sDate)
                .lt(MobileSms::getSmsAddTime, eDate);
        return count(wrapper);
    }

    @Override
    public MobileSms select1(Long smsId, Integer smsStatus) {
        LambdaQueryWrapper<MobileSms> wrapper = Wrappers.lambdaQuery(MobileSms.class);
        wrapper.select(MobileSms::getSmsMobile, MobileSms::getSmsContent)
                .eq(MobileSms::getSmsId, smsId)
                .eq(MobileSms::getSmsStatus, smsStatus);
        MobileSms one = getOne(wrapper);
        return one;
    }

}
